package com.ruoyi.adapayBalance.controller;

import java.util.List;

import com.ruoyi.common.utils.SecurityUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.constant.DicConstants;
import com.ruoyi.adapayBalance.domain.AdapayBalance;
import com.ruoyi.adapayBalance.service.IAdapayBalanceService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 余额记录Controller
 *
 * @author ch
 * @date 2022-02-28
 */
@RestController
@RequestMapping("/adapayBalance/adapayBalance")
public class AdapayBalanceController extends BaseController
{
    @Autowired
    private IAdapayBalanceService adapayBalanceService;

    /**
     * 查询余额记录列表
     */
    @PreAuthorize("@ss.hasPermi('adapayBalance:adapayBalance:list')")
    @GetMapping("/list")
    public TableDataInfo list(AdapayBalance adapayBalance)
    {
        startPage();
        List<AdapayBalance> list = adapayBalanceService.selectAdapayBalanceList(adapayBalance);
        return getDataTable(list);
    }

    /**
     * 导出余额记录列表
     */
    @PreAuthorize("@ss.hasPermi('adapayBalance:adapayBalance:export')")
    @Log(title = "余额记录", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(AdapayBalance adapayBalance)
    {
        List<AdapayBalance> list = adapayBalanceService.selectAdapayBalanceList(adapayBalance);
        ExcelUtil<AdapayBalance> util = new ExcelUtil<AdapayBalance>(AdapayBalance.class);
        return util.exportExcel(list, "余额记录数据");
    }

    /**
     * 获取余额记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('adapayBalance:adapayBalance:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(adapayBalanceService.selectAdapayBalanceById(id));
    }

    /**
     * 新增余额记录
     */
    @PreAuthorize("@ss.hasPermi('adapayBalance:adapayBalance:add')")
    @Log(title = "余额记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody AdapayBalance adapayBalance)
    {
        return toAjax(adapayBalanceService.insertAdapayBalance(adapayBalance));
    }

    /**
     * 修改余额记录
     */
    @PreAuthorize("@ss.hasPermi('adapayBalance:adapayBalance:edit')")
    @Log(title = "余额记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody AdapayBalance adapayBalance)
    {
        adapayBalance.setUpdateType(DicConstants.BUSINESS_Manager.getCode());
        return toAjax(adapayBalanceService.updateAdapayBalance(adapayBalance));
    }

    /**
     * 删除余额记录
     */
    @PreAuthorize("@ss.hasPermi('adapayBalance:adapayBalance:remove')")
    @Log(title = "余额记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(adapayBalanceService.logicDeleteAdapayBalance(ids,DicConstants.BUSINESS_Manager.getCode(),SecurityUtils.getUserId()));
    }
}
